package com.kimwu.kill.mall.order.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;
import com.kimwu.kill.mall.order.web.entity.OrderInfo;
import com.kimwu.kill.mall.order.web.mapper.OrderInfoMapper;
import com.kimwu.kill.mall.order.web.service.IOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author KimWu
 * @since 2021-08-26
 */
@Service
@Slf4j
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements IOrderInfoService {

    {
        IdGeneratorOptions options = new IdGeneratorOptions((short) 1);
        YitIdHelper.setIdGenerator(options);
    }

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Override
    @Async("taskExecutor")
    public void saveAsync(OrderInfo orderInfo) {
        try {
            orderInfo.setOrderNo(YitIdHelper.nextId() + "");
            orderInfoMapper.insert(orderInfo);
        } catch (Exception e) {
            //失败时可以做扩展方法，此处只打印日志
            log.info("写入订单失败:{}", orderInfo.toString());
        }
    }
}
